<?php
namespace Inbox\Model;

use Zend\Db\Adapter\Adapter;
//use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Insert;
use Zend\Db\Sql\Update;
use Zend\Db\Sql\Delete;
use Zend\InputFilter\Factory as InputFactory;     // <-- Add this import
use Zend\InputFilter\InputFilter;                 // <-- Add this import
use Zend\InputFilter\InputFilterAwareInterface;   // <-- Add this import
use Zend\InputFilter\InputFilterInterface;        // <-- Add this import

class InboxTable extends AbstractTableGateway //implements InputFilterAwareInterface


{
    protected $table = 'inbox';
	

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
    }

    public function fetchAll()
    {
        $resultSet = $this->select(function (Select $select) {
                    $select->order('id ASC');
                });
        $entities = array();
        foreach ($resultSet as $row) {
            $entity = new Entity\Conversation();
            $entity->setSubject($row->subject)
                   ->setDescription($row->description)
                   ->setAccount($row->account_id)
                   ->setOpportunity($row->opportunity_id);
            $entities[] = $entity;
        }
        return $entities;
    }
	
	public function search($some)
	{
		$resultSet = $this->select(function (Select $select) {
                    $select->where->like('name','%'.$some.'%');
                });
        $entities = array();
        foreach ($resultSet as $row) {
            $entity = new Entity\Conversation();
            $entity->setSubject($row->subject)
                   ->setDescription($row->description)
                   ->setAccount($row->account_id)
                   ->setOpportunity($row->opportunity_id);
            $entities[] = $entity;
        }
        return $entities;
	}

    public function getInbox($id)
    {
        $id  = (int) $id;
        $rowset = $this->tableGateway->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }

   
    
 }
?>